#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2020/9/20 18:46
# @Author  : leon yan
# @Site    : 
# @File    : SheetTBL.py
# @Software: PyCharm

from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import (QApplication, QMainWindow)

import Globalist as gl
from lib.qpulsesignal import Qpulsesignal
from resource.SheetTBL_ui import Ui_QWFormTable


class QSheetTBL(QMainWindow, Ui_QWFormTable):

    def __init__(self, DbTblName=None, parent=None, *args, **kwargs):
        super().__init__(parent, *args, **kwargs)
        self.setupUi(self)
        self.DbTblName = DbTblName
        self.setWindowTitle(DbTblName)

        '''判断是否是开发者模式'''
        self.widget.frame.setVisible(False)
        self._DeveloperMode()
        '''启动脉冲线程'''
        self.PulseSignal = Qpulsesignal()
        self.PulseSignal.start()
        self.PulseSignal.bPulse.connect(self.do_UpdateStatus)

    def __del__(self):
        print("SheetTBL is deleted")

    def _DeveloperMode(self):
        """在About界面是否登入为超级用户"""
        if gl.get_value("Admin") == 2:
            self.widget.setTableSheet(self.DbTblName, True)
        else:
            self.widget.setTableSheet(self.DbTblName, False)

    @pyqtSlot()
    def on_btnAdd_clicked(self):
        self.widget.do_Add()

    @pyqtSlot()
    def on_btnInsert_clicked(self):
        self.widget.do_Insert()

    @pyqtSlot()
    def on_btnDel_clicked(self):
        self.widget.do_Del()

    @pyqtSlot()
    def on_btnSave_clicked(self):
        self.widget.do_Update()

    @pyqtSlot()
    def on_btnUpLoad_clicked(self):
        self.widget.do_UpLoad()

    @pyqtSlot()
    def on_btnDownLoad_clicked(self):
        self.widget.do_DownLoad()

    @pyqtSlot()
    def on_btnAddUser_clicked(self):
        self.widget.do_AddUser()

    @pyqtSlot()
    def on_btnPswChange_clicked(self):
        self.widget.do_ChangePsw()

    '''更新表数据'''
    @pyqtSlot()
    def do_UpdateStatus(self):
        self.widget.do_UpdateParameter()


if __name__ == '__main__':
    import sys

    app = QApplication(sys.argv)
    objWindow = QSheetTBL('')

    objWindow.show()
    sys.exit(app.exec_())
